package com.sun.lib;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.CheckBox;

import androidx.appcompat.widget.AppCompatCheckBox;

import com.sun.lib.helper.SCheckHelper;

public class SCheckBox extends AppCompatCheckBox implements SHelper<SCheckHelper> {
    private SCheckHelper mHelper;

    public SCheckBox(Context context) {
        this(context, null);
    }

    public SCheckBox(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SCheckBox(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mHelper = new SCheckHelper(context, this, attrs);
        setClickable(true);
    }

    @Override
    public SCheckHelper getHelper() {
        return mHelper;
    }

    @Override
    public void setCornerRadius(float radius) {
        mHelper.setmCornerRadius(radius);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if(mHelper!=null) mHelper.drawIconWithText();
    }

    @Override
    public void setChecked(boolean checked) {
        super.setChecked(checked);
        if (mHelper != null)
            mHelper.setChecked(checked);
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        if (mHelper != null)
            mHelper.setEnabled(enabled);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if(mHelper!=null) mHelper.onSizeChanged(w, h, oldw, oldh);
    }
}
